/**
 * 
 */
package kr.pe.smallhope.mobismap.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

/**
 * @author silent
 *
 */
public class MenuView extends ViewPart {
    public static final String ID = MenuView.class.getName();
    
    /**
     * 
     */
    public MenuView() {
        // TODO Auto-generated constructor stub
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createPartControl(Composite parent) {
        parent.setLayout(new GridLayout(5, true));
        parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
        
        createMenuItem(parent, "Naver Address to Coordinate", NaverAddressCoordinateView.ID);
        createMenuItem(parent, "Naver Distance && Time", NaverDistanceTimeView.ID);
        createMenuItem(parent, "Google Address to Coordinate", GoogleAddressCoordinateView.ID);
        createMenuItem(parent, "Google Distance && Time", GoogleDistanceTimeView.ID);
        createMenuItem(parent, "Naver Mark on Map", NaverMapView.ID);
    }
    
    private void createMenuItem(Composite parent, String text, final String viewId) {
        Button menuItem = new Button(parent, SWT.None);
        menuItem.setText(text);
        GridData gd = new GridData(SWT.CENTER, SWT.CENTER, true, true);
        menuItem.setLayoutData(gd);
        menuItem.addSelectionListener(new SelectionAdapter(){
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent event) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart viewPart = page.findView(viewId);
                if (viewPart != null) {
                    try {
                        page.showView(viewId);
                    } catch (PartInitException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
     */
    @Override
    public void setFocus() {
        // TODO Auto-generated method stub
        
    }
    
}
